package org.devops

def Email(status,env, emailUser, jobName, branch, buildUser, buildTime, buildDuration, rollback, deployTarget, deployInfo, srcURL,isBuildStage = false) {
    def subject = isBuildStage ? "${env}环境 - ${jobName} CI构建通知" : "${env}环境 - ${jobName} - ${rollback ? '回滚' : '发布'}结果: ${status}"
    
    emailext body: """
        <!DOCTYPE html>
        <html>
        <head>
        <meta charset="UTF-8">
        <style>
            body { font-family: Arial, sans-serif; line-height: 1.6 }
            .header { color: #CC0000; font-weight: bold }
            .info { margin: 10px 0 }
            ul { padding-left: 20px }
            li { margin: 5px 0 }
            a { color: #0066CC }
        </style>
        </head>
        <body>
            <img src="https://www.jenkins.io/images/logos/fire/fire.svg" width="100"><br>
            <div class="header">${jobName} ${rollback ? '回滚' : '发布'}通知</div>
            <hr>
            <div class="info">
                <ul>
                    <li><b>项目名称:</b> ${jobName}</li>
                    <li><b>${rollback ? '回滚版本' : '发布版本'}:</b> ${deployInfo}</li>
                    <li><b>部署目标:</b> ${deployTarget}</li>
                    <li><b>代码仓库:</b> ${srcURL}</li>
                    <li><b>构建分支:</b> ${branch}</li>
                    <li><b>构建用户:</b> ${buildUser}</li>
                    <li><b>构建结果:</b> <span style="color:${status == 'SUCCESS' ? 'green' : 'red'}">${status}</span></li>
                    <li><b>构建时间:</b> ${buildTime}</li>
                    <li><b>持续时间:</b> ${buildDuration}</li>
                    <li><b>构建详情:</b> <a href="${BUILD_URL}">查看详情</a></li>
                    <li><b>构建日志:</b> <a href="${BUILD_URL}console">查看日志</a></li>
                </ul>
            </div>
            <hr>
            <div style="color: #666; font-size: 0.9em">
                本邮件由系统自动发送，请勿直接回复
            </div>
        </body>
        </html>
    """,
    subject: subject,
    to: emailUser
}